#include "stdafx.h"
#include "AbilityPropertyPage.h"
#include "Ability.h"
#include "Property.h"

#include <utility/Config.h>
#include <utility/Streams.h>

#ifdef WIN32
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#endif

namespace serika
{
	namespace dq
	{
		AbilityPropertyPage::AbilityPropertyPage(PropertyTemplate* tmpl)
			: PropertyPage(tmpl)
		{
		}

		AbilityPropertyPage::~AbilityPropertyPage()
		{
		}

		void AbilityPropertyPage::OnInitialize()
		{
			this->CreateCombo(mCombo, CBS_DROPDOWNLIST);
			const std::vector<Ability>& abilities = Ability::GetAllAbilities();
			for (std::vector<Ability>::const_iterator itr = abilities.begin();
				itr != abilities.end(); ++itr)
			{
				mCombo.InsertString(itr->GetId()-1, itr->GetName().c_str());
			}
			this->CreateEdit(mEdit, true);
		}

		void AbilityPropertyPage::DoLayout(ut::Config* config)
		{
			this->Layout(&mCombo, config, _T("Combo"));
			this->Layout(&mEdit, config, _T("Edit"));
		}

		Property* AbilityPropertyPage::CreateProperty()
		{
			int id = mCombo.GetCurSel() + 1;
			CString text;
			mEdit.GetWindowText(text);
			ut::Sstream ss;
			ss << text.GetBuffer();
			int ability = 0;
			ss >> ability;
			mCombo.GetWindowText(text);
			return Property::NewProperty(0, id, ability, 0, ut::String(text), mTmpl);
		}

		void AbilityPropertyPage::OnActivate()
		{
		}

		void AbilityPropertyPage::OnDeactivate()
		{
		}
	}
}
